package cn.johnyu.demo;

import cn.johnyu.demo.dao.BookDao;
import cn.johnyu.demo.dao.impl.BookDaoImpl;
import cn.johnyu.demo.pojo.Book;
import com.google.gson.Gson;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@WebServlet(name = "findBooksServlet", value = "/api/findBooks")
public class FindBooksServlet extends HttpServlet {
    private BookDao bookDao=new BookDaoImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Book> books = bookDao.findAll();
        req.setAttribute("books", books);
        req.getRequestDispatcher("/WEB-INF/jsp/books.jsp").forward(req, resp);
    }
}
